package com.gmail.blackdog1987.carcare.util;

import android.util.Log;

/**
 * 
 * @author 董国超
 *
 */
public class LogUtil {

	private static int sLevel = Log.VERBOSE;

	/**
	 * 设置日志级别。
	 * 
	 * @param level 日志级别。<br/>
	 *            {@link android.util.Log#VERBOSE Log.VERBOSE}<br/>
	 *            {@link android.util.Log#DEBUG Log.DEBUG}<br/>
	 *            {@link android.util.Log#INFO Log.INFO}<br/>
	 *            {@link android.util.Log#WARN Log.WARN}<br/>
	 *            {@link android.util.Log#ERROR Log.ERROR}<br/>
	 *            {@link android.util.Log#ASSERT Log.ASSERT}
	 */
	public static void setLogLevel(int level) {
		sLevel = level;
	}

	/**
	 * Send a {@link android.util.Log#VERBOSE VERBOSE} log message.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @see android.util.Log#v(String, String) Log.v(String, String)
	 */
	public static void v(String tag, String msg) {
		if (sLevel <= Log.VERBOSE) {
			Log.v(String.valueOf(tag), String.valueOf(msg));
		}
	}

	/**
	 * Send a {@link android.util.Log#VERBOSE VERBOSE} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @param tr An exception to log.
	 * @see android.util.Log#v(String, String, Throwable) Log.v(String, String, Throwable)
	 */
	public static void v(String tag, String msg, Throwable tr) {
		if (sLevel <= Log.VERBOSE) {
			Log.v(String.valueOf(tag), String.valueOf(msg), tr);
		}
	}

	/**
	 * Send a {@link android.util.Log#DEBUG DEBUG} log message.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @see android.util.Log#d(String, String) Log.d(String, String)
	 */
	public static void d(String tag, String msg) {
		if (sLevel <= Log.DEBUG) {
			Log.d(String.valueOf(tag), String.valueOf(msg));
		}
	}

	/**
	 * Send a {@link android.util.Log#DEBUG DEBUG} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @param tr An exception to log.
	 * @see android.util.Log#d(String, String, Throwable) Log.d(String, String, Throwable)
	 */
	public static void d(String tag, String msg, Throwable tr) {
		if (sLevel <= Log.DEBUG) {
			Log.d(String.valueOf(tag), String.valueOf(msg), tr);
		}
	}

	/**
	 * Send an {@link android.util.Log#INFO INFO} log message.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @see android.util.Log#i(String, String) Log.i(String, String)
	 */
	public static void i(String tag, String msg) {
		if (sLevel <= Log.INFO) {
			Log.i(String.valueOf(tag), String.valueOf(msg));
		}
	}

	/**
	 * Send a {@link android.util.Log#INFO INFO} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @param tr An exception to log.
	 * @see android.util.Log#i(String, String, Throwable) Log.i(String, String, Throwable)
	 */
	public static void i(String tag, String msg, Throwable tr) {
		if (sLevel <= Log.INFO) {
			Log.i(String.valueOf(tag), String.valueOf(msg), tr);
		}
	}

	/**
	 * Send a {@link android.util.Log#WARN WARN} log message.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @see android.util.Log#w(String, String) Log.w(String, String)
	 */
	public static void w(String tag, String msg) {
		if (sLevel <= Log.WARN) {
			Log.w(String.valueOf(tag), String.valueOf(msg));
		}
	}

	/**
	 * Send a {@link android.util.Log#WARN WARN} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @param tr An exception to log.
	 * @see android.util.Log#w(String, String, Throwable) Log.w(String, String, Throwable)
	 */
	public static void w(String tag, String msg, Throwable tr) {
		if (sLevel <= Log.WARN) {
			Log.w(String.valueOf(tag), String.valueOf(msg), tr);
		}
	}

	/**
	 * Send a {@link android.util.Log#WARN WARN} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param tr An exception to log.
	 * @see android.util.Log#w(String, Throwable) Log.w(String, Throwable)
	 */
	public static void w(String tag, Throwable tr) {
		if (sLevel <= Log.WARN) {
			Log.w(String.valueOf(tag), tr);
		}
	}

	/**
	 * Send an {@link android.util.Log#ERROR ERROR} log message.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @see android.util.Log#e(String, String) Log.w(String, String)
	 */
	public static void e(String tag, String msg) {
		if (sLevel <= Log.ERROR) {
			Log.e(String.valueOf(tag), String.valueOf(msg));
		}
	}

	/**
	 * Send a {@link android.util.Log#ERROR ERROR} log message and log the exception.
	 * 
	 * @param tag Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs.
	 * @param msg The message you would like logged.
	 * @param tr An exception to log.
	 * @see android.util.Log#e(String, String, Throwable) Log.e(String, String, Throwable)
	 */
	public static void e(String tag, String msg, Throwable tr) {
		if (sLevel <= Log.ERROR) {
			Log.e(String.valueOf(tag), String.valueOf(msg), tr);
		}
	}

}
